//
//  NSString+YHSHA_1.m
//  UI24_加密
//
//  Created by dllo on 16/8/16.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "NSString+YHSHA_1.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (YHSHA_1)

- (NSString *)stringWithSHA_1 {
    // 将字符串转化为C语言字符串求长度
    const char *cString = [self UTF8String];
    CC_LONG len = (CC_LONG)strlen(cString);
    unsigned char bytes[CC_SHA1_DIGEST_LENGTH];
    // SHA_1 转化
    CC_SHA1(cString, len, bytes);
    NSMutableString *str1 = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH];
    for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) {
        [str1 appendFormat:@"%02x", bytes[i]];
    }
    return str1;
}

@end
